package cn.iocoder.yudao.module.engine.enums;

import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.StringArrayValuable;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;

/**
 * Sensor类型枚举
 * 优先级值越小的，优先级越高。
 */
@AllArgsConstructor
@ToString
public enum SensorTypeEnum implements StringArrayValuable {
    THREE_AXIS("ThreeAxis", 2, "三轴传感器"),
    ;

    public static final String[] ARRAYS = Arrays.stream(values())
            .map(SensorTypeEnum::getValue)
            .toArray(String[]::new);

    /**
     * 类型
     */
    private final String value;

    /**
     * 优先级
     */
    private final int priority;

    /**
     * 类型名
     */
    private final String name;

    @JsonGetter
    public static SensorTypeEnum fromValue(String value) {
        final SensorTypeEnum sensorTypeEnum = ArrayUtil.firstMatch(v -> v.getValue().equals(value), SensorTypeEnum.values());
        if (sensorTypeEnum == null) {
            throw ServiceExceptionUtil.exception(EnumEngineAipError.DEFAULT_ERROR, "未知的SensorType: " + value);
        }
        return sensorTypeEnum;
    }

    public int getPriority() {
        return priority;
    }

    @JsonValue
    public String getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    @Override
    public String[] array() {
        return ARRAYS;
    }
}
